package com.zb.scheduletask;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
import java.text.MessageFormat;

@Aspect
@Component
public class Log4ScheduledTask
{
	private Log log = LogFactory.getLog(Log4ScheduledTask.class);

	@Before("executeMethod()")
	public void logBefore(JoinPoint joinPoin)
	{
		log.info(MessageFormat.format("-------Scheduled task: {0} start to run-------", joinPoin.getTarget().getClass().getSimpleName()));
	}

	@After("executeMethod()")
	public void logAfter(JoinPoint joinPoin)
	{
		log.info(MessageFormat.format("-------Scheduled task: {0} finished-------", joinPoin.getTarget().getClass().getSimpleName()));
	}

	@Pointcut("execution(* com.zb.scheduletask.ScheduledTask.execute())")
	private void executeMethod()
	{
	}

}
